package com.tms.app.tms.ui.home.msg;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.tms.app.tms.ui.base.ui.BaseFragment;
import com.tms.app.tms.R;
import com.tms.app.tms.adapter.MyViewPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by happy on 2017/8/26.
 */

public class OrderFt extends BaseFragment {
    Unbinder unbinder;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.tab_layout)
    TabLayout tabLayout;
    @BindView(R.id.viewPager)
    ViewPager viewPager;
    private List<String> listTile=new ArrayList<>();
    private List<Fragment> fragmentList=new ArrayList<>();

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.layout_fragment_order, null);

        unbinder = ButterKnife.bind(this, rootView);
        initView();
        setToolBarTitle(rootView,"消息中心",0,0);
        return rootView;
    }


    private void initView() {
        tabLayout.addTab(tabLayout.newTab().setText("已拒绝"));
        tabLayout.addTab(tabLayout.newTab().setText("已完成"));
      //  tabLayout.addTab(tabLayout.newTab().setText("未完成"));
//        orderAdapter = new OrderAdapter(list);
//        LinearLayoutManager mgr = new LinearLayoutManager(getActivity());
//        recyclerView.setLayoutManager(mgr);
//        recyclerView.setNestedScrollingEnabled(false);
//        recyclerView.setAdapter(orderAdapter);

        listTile.add("任务消息");
        listTile.add("变更通知");
        listTile.add("系统消息");
       // listTile.add("未完成");


        fragmentList.add(new OrderChildFt());
        fragmentList.add(new MsgChangeFt());
        fragmentList.add(new OrderChildMsgFt());
     //   fragmentList.add(new OrderChildFt());

        MyViewPagerAdapter adapter=new MyViewPagerAdapter(getChildFragmentManager(),listTile,fragmentList);

        viewPager.setAdapter(adapter);
        viewPager.setOffscreenPageLimit(3);
        tabLayout.setupWithViewPager(viewPager);
        //使用ViewPager的适配器
        tabLayout.setTabsFromPagerAdapter(adapter);
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


    @Override
    public void handlerErrorMsg(int errorCode) {

    }
}
